﻿<Page x:Class="SqlMetalIncludeGUI.ConfigureDatabase"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:Me="clr-namespace:SqlMetalIncludeGUI"
    Title="SqlMetalInclude GUI"
      x:Name="_this">
    <Page.Resources>
        <Me:Config x:Key="Config" />
    </Page.Resources>
    <DockPanel>
        <StackPanel Orientation="Horizontal" HorizontalAlignment="Right" DockPanel.Dock="Bottom">
            <Button Margin="5" x:Name="TestConnectionButton" Click="TestConnectionClick" Content="Test connection" />
            <Button Margin="5" Content="Continue" x:Name="NextButton" Click="NextButtonClick"
                    IsEnabled="{Binding Source={StaticResource Config}, Path=Default.SqlConfigValid}"/>
        </StackPanel>
        <GroupBox Header="Sql configuration">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="1*" />
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>
                <TextBlock Text="Server: " VerticalAlignment="Center" Margin="3" Grid.Column="0" Grid.Row="0" />
                <ComboBox 
                    Margin="3" 
                    Grid.Column="1" 
                    Grid.Row="0" 
                    x:Name="SqlServerName"  
                    IsEditable="True" 
                    DropDownOpened="SqlServerNameDropDownOpened"
                    ItemsSource="{Binding ElementName=_this, Path=Servers}"
                    DisplayMemberPath="Name"
                    Text="{Binding Source={StaticResource Config}, Path=Default.SqlServer, UpdateSourceTrigger=PropertyChanged}"
                    />
                <TextBlock Text="Database: " VerticalAlignment="Center" Margin="3" Grid.Column="0" Grid.Row="1" />
                <ComboBox 
                    Margin="3"
                    Grid.Column="1" 
                    Grid.Row="1" 
                    x:Name="SqlDatabaseName" 
                    IsEditable="True"
                    DropDownOpened="SqlDatabaseNameDropDownOpened"
                    ItemsSource="{Binding ElementName=_this, Path=Databases}"
                    DisplayMemberPath="Name"
                    Text="{Binding Source={StaticResource Config}, Path=Default.SqlDatabase, UpdateSourceTrigger=PropertyChanged}"
                    />
                <GroupBox Header="Authentication:" Grid.Column="0" Grid.Row="2" Grid.ColumnSpan="3" >
                    <StackPanel>
                        <RadioButton Content="Windows Authentication" Margin="3" x:Name="SqlAuthTypeWindows"
                                     IsChecked="{Binding Source={StaticResource Config}, Path=Default.WindowsAuth, UpdateSourceTrigger=PropertyChanged}"/>
                        <RadioButton Content="Sql Authentication" Margin="3" x:Name="SqlAuthTypeSql"
                                     IsChecked="{Binding Source={StaticResource Config}, Path=Default.SqlAuth, UpdateSourceTrigger=PropertyChanged}"/>
                        <Grid Visibility="{Binding Source={StaticResource Config}, Path=Default.SqlAuth, Converter={StaticResource BooleanToVisibilityConverter}}">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition Width="1*" />
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto" />
                                <RowDefinition Height="Auto" />
                            </Grid.RowDefinitions>
                            <TextBlock Text="Username: " Grid.Column="0" Grid.Row="0" Margin="3" VerticalAlignment="Center" />
                            <TextBox Grid.Column="1" Grid.Row="0" Margin="3" x:Name="SqlUsername"
                                     Text="{Binding Source={StaticResource Config}, Path=Default.Username, UpdateSourceTrigger=PropertyChanged}"/>
                            <TextBlock Text="Password: " Grid.Column="0" Grid.Row="1" Margin="3" VerticalAlignment="Center" />
                            <TextBox Grid.Column="1" Grid.Row="1" Margin="3" x:Name="SqlPassword"
                                     Text="{Binding Source={StaticResource Config}, Path=Default.Password, UpdateSourceTrigger=PropertyChanged}"/>
                        </Grid>
                    </StackPanel>
                </GroupBox>
            </Grid>
        </GroupBox>
    </DockPanel>
</Page>
